package com.sctvcloud.renhe.ui.fragment;

import android.content.Intent;
import android.os.Bundle;
import android.os.Handler;
import android.os.Message;
import android.os.SystemClock;
import android.support.annotation.Nullable;
import android.support.v7.widget.DefaultItemAnimator;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.text.TextUtils;
import android.util.ArrayMap;
import android.util.Pair;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.view.animation.Animation;
import android.view.animation.AnimationUtils;
import android.view.animation.TranslateAnimation;
import android.widget.ImageView;
import android.widget.RelativeLayout;
import android.widget.Toast;

import com.canyinghao.canrefresh.CanRefreshLayout;
import com.gridsum.tracker.GridsumWebDissector;
import com.jiongbull.jlog.JLog;
import com.ruihang.generalibrary.ui.dialog.BaseDialogFragment;
import com.ruihang.generalibrary.ui.util.OnItemInternalClick;
import com.ruihang.generalibrary.utils.DateUtils;
import com.ruihang.generalibrary.utils.GroupOrderHelperSingled;
import com.ruihang.generalibrary.utils.ListUtils;
import com.ruihang.generalibrary.utils.SharedPreferencesUtil;
import com.ruihang.generalibrary.utils.UrlUtils;
import com.sctvcloud.renhe.R;
import com.sctvcloud.renhe.base.BaseActivity;
import com.sctvcloud.renhe.application.Constances;
import com.sctvcloud.renhe.application.Cache;
import com.sctvcloud.renhe.beans.ADynamicsItem;
import com.sctvcloud.renhe.beans.AdvertBean;
import com.sctvcloud.renhe.beans.AdvertDataVo;
import com.sctvcloud.renhe.beans.FUsers;
import com.sctvcloud.renhe.beans.FocusColumn;
import com.sctvcloud.renhe.beans.HomeListItem;
import com.sctvcloud.renhe.beans.HomeLive;
import com.sctvcloud.renhe.beans.HomePopular;
import com.sctvcloud.renhe.beans.LiveItem;
import com.sctvcloud.renhe.beans.NewsDate;
import com.sctvcloud.renhe.beans.NewsItem;
import com.sctvcloud.renhe.beans.SingleResult;
import com.sctvcloud.renhe.beans.Titles;
import com.sctvcloud.renhe.http.AbsListNetCallback;
import com.sctvcloud.renhe.http.AbsNetCallBack;
import com.sctvcloud.renhe.http.NetUtils;
import com.sctvcloud.renhe.ui.activities.AnchorActivity;
import com.sctvcloud.renhe.ui.activities.CommentDetailActivity;
import com.sctvcloud.renhe.ui.activities.CommodityDetailActivity;
import com.sctvcloud.renhe.ui.activities.FloatAdActivity;
import com.sctvcloud.renhe.ui.activities.IntegralStoreActivity;
import com.sctvcloud.renhe.ui.activities.LoginActivity;
import com.sctvcloud.renhe.ui.activities.MainActivity;
import com.sctvcloud.renhe.ui.activities.NewesDetailActivity;
import com.sctvcloud.renhe.ui.activities.TYFOH5Activity;
import com.sctvcloud.renhe.ui.adapter.AnchorHomePageAdapter;
import com.sctvcloud.renhe.ui.adapter.GreatestAdapter;
import com.sctvcloud.renhe.ui.adapter.holder.HomeAnchorEntranceHolder;
import com.sctvcloud.renhe.ui.adapter.holder.HomeAnchorHolder;
import com.sctvcloud.renhe.ui.adapter.holder.HomeLiveHolder;
import com.sctvcloud.renhe.ui.adapter.holder.HomeSpecialHolder;
import com.sctvcloud.renhe.ui.dialog.NetModeDiaFragment;
import com.sctvcloud.renhe.ui.util.IListShowData;
import com.sctvcloud.renhe.ui.util.NewsDateComparator;
import com.sctvcloud.renhe.ui.utils.GlideUtil;
import com.sctvcloud.renhe.ui.utils.GreatestDataAddHelper;
import com.sctvcloud.renhe.ui.utils.MutilDateNewsGetHelper;
import com.sctvcloud.renhe.ui.utils.SkipUtil;
import com.sctvcloud.renhe.ui.utils.UIUtils;
import com.sctvcloud.renhe.ui.widget.BasePlayerView;
import com.sctvcloud.renhe.utils.ListTypeUtils;
import com.sctvcloud.renhe.utils.UserManager;

import org.xutils.common.util.DensityUtil;

import java.sql.Date;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.Collections;
import java.util.HashMap;
import java.util.List;

import butterknife.BindView;
import butterknife.ButterKnife;

/**
 * Created by Administrator on 2017/6/29 0029.
 * 首页 精选页面
 */
public class GreatestFragment extends ColumnBaseFragment implements CanRefreshLayout.OnRefreshListener
        , CanRefreshLayout.OnLoadMoreListener, HomeSpecialHolder.OnSpecialSelectMoreListener , HomeLiveHolder.OnLivePlayingListener{
    public static final String FLOAT_AD_SHOW = "is_float_ad_show";
    private static final int CODE_REQUEST_LOGIN = 1;
    private static final int WHAT_GET_EXPRESS = 551;
    private static final long SPACE_GET_EXPRESS = 60000L;

    @BindView(R.id.common_refresh)
    protected CanRefreshLayout refreshLayout;
    @BindView(R.id.can_content_view)
    protected RecyclerView recyclerView;
    @BindView(R.id.ad_layer_layout)
    protected RelativeLayout adLayerLayout;
    @BindView(R.id.ad_layer)
    protected ImageView adLayer;
    @BindView(R.id.close_ad)
    protected ImageView adClose;

    private LinearLayoutManager layoutManager;
    private GreatestAdapter adapter;

    private GreatestDataAddHelper dataAddHelper;

    private GroupOrderHelperSingled groupOrderHelper;

    private String hour24UrlTemp, bannerUrlTemp, liveUrlTemp, expressUrlTemp, popularUrlTemp, specialUrlTemp, anchorsUrlTemp;
    private int current24Page = -1, secTitlePos = -1;
    private Date first24TitleDateTemp;

    private MutilDateNewsGetHelper hour24GetHelper;
    private int newsFlashType = 0;
    private List<IListShowData> newsList = new ArrayList<>();
    private boolean isReset;
    private String news24Domain = "";
    private Handler handler;

    //    private LittleLifeManager littleLifeManager;

    private long lastGetTime = -1;
    private boolean isFirst = false;
    private boolean isShowLuZhou = false;
    private int newKey = GreatestAdapter.VIEWTYPE_NEWS_24;
    private boolean isRefresh = false;
    private long dyHeight = 0;
    private AdvertBean bottomAdBean;//精选底部广告
    private Animation mIntoAction;
    private Animation mOutAction;
//    private String anchorChannelUrl;

    @Override
    public void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

        isFirst = (boolean) SharedPreferencesUtil.getParam(getActivity(), FLOAT_AD_SHOW, false);
        handler = new Handler() {
            @Override
            public void handleMessage(Message msg) {
                super.handleMessage(msg);
                if (msg != null) {
                    parseMsg(msg);
                }
            }
        };

    }

    @Nullable
    @Override
    public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
        View view = inflater.inflate(R.layout.fragment_greatest, container, false);
        ButterKnife.bind(this, view);
        return view;
    }

    @Override
    public void onResume() {
        super.onResume();
        if (null != adapter) {
            LinearLayoutManager layoutManager = (LinearLayoutManager) recyclerView.getLayoutManager();
            for (int i = 0; i < adapter.getItemCount(); i++) {
                View topView = layoutManager.findViewByPosition(i);
                if (null != topView && recyclerView.getChildViewHolder(topView) instanceof HomeLiveHolder) {
                    HomeLiveHolder liveHolder = (HomeLiveHolder) recyclerView.getChildViewHolder(topView);
                    liveHolder.onPrepared();
                    break;
                }
            }
        }
//        JLog.e("okh  parent=" + isParentShowing + "  this=" + isThisShowing + "  count=" + getShowCount() + "  front=" + isFront);
    }

    @Override
    public void onRefresh() {
        releaseLive();
        if (Cache.getInstance().isCityShow()) {
            String news24Url = Cache.getInstance().getChoosedCityNewsUrl();
            news24Domain = UIUtils.getDomain(news24Url);
        } else {
            news24Domain = "";
        }
        isRefresh = true;
        //首次加载数据，或之后下拉刷新
        getChannelList();
    }

    @Override
    public void onLoadMore() {
        if (Cache.getInstance().isCityShow()) {
            String news24Url = Cache.getInstance().getChoosedCityNewsUrl();
            news24Domain = UIUtils.getDomain(news24Url);
        } else {
            news24Domain = "";
        }
        if (groupOrderHelper.getCount() <= 0) {
            getNews24Page(news24Domain, false);
        } else {
            if (refreshLayout.isRefreshing()) {
                refreshLayout.loadMoreComplete();
            }
        }
    }

    /**
     * 下拉刷新时释放正在直播的内容
     */
    private void releaseLive() {
        if (null != adapter) {
            LinearLayoutManager layoutManager = (LinearLayoutManager) recyclerView.getLayoutManager();
            for (int i = 0; i < adapter.getItemCount(); i++) {
                View topView = layoutManager.findViewByPosition(i);
                if (null != topView && recyclerView.getChildViewHolder(topView) instanceof HomeLiveHolder) {
                    HomeLiveHolder liveHolder = (HomeLiveHolder) recyclerView.getChildViewHolder(topView);
                    liveHolder.onIDestory();
                    break;
                }
            }
        }
    }


    @Override
    protected void initViews(View v, @Nullable Bundle savedInstanceState) {
        layoutManager = new LinearLayoutManager(getContext(), LinearLayoutManager.VERTICAL, false);
        recyclerView.setLayoutManager(layoutManager);
        recyclerView.setItemAnimator(new DefaultItemAnimator());
//        sss();
//        adapter = dataAddHelper.getAdapter(getContext());
//        adapter.setBannerActiveClick(activeClick);
//        recyclerView.setAdapter(adapter);
        refreshLayout.setOnRefreshListener(this);
        refreshLayout.setOnLoadMoreListener(this);
        refreshLayout.setLoadMoreEnabled(false);
        groupOrderHelper = new GroupOrderHelperSingled();
        adLayerLayout.setVisibility(View.GONE);
        mIntoAction = AnimationUtils.loadAnimation(getContext(), R.anim.ad_into_animation);
        mOutAction = AnimationUtils.loadAnimation(getContext(), R.anim.ad_out_animation);
        adClose.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                adLayerLayout.setVisibility(View.GONE);
                adLayerLayout.startAnimation(mOutAction);
                Cache.getInstance().setHomeGreateAdClosed(true);
            }
        });
        adLayer.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                // 底部广告跳转
                if (null != bottomAdBean) {
                    if (bottomAdBean.getAdType() == 1) {
                        //新闻
                        if (ListUtils.isListValued(bottomAdBean.getNewsUrlList())) {
                            Intent intent = new Intent(getContext(), NewesDetailActivity.class);
                            intent.putExtra(BaseActivity.EX_URL, bottomAdBean.getNewsUrlList().get(0).getNewsUrl());
                            startActivity(intent);
                        }
                        adLayerLayout.setVisibility(View.GONE);
                        adLayerLayout.startAnimation(mOutAction);
                        Cache.getInstance().setHomeGreateAdClosed(true);
                    } else if (bottomAdBean.getAdType() == 2) {
                        //商品广告
                        if (null != UserManager.getInstance().getUser()) {
                            String url = bottomAdBean.getProductUrl();
                            String json = bottomAdBean.getProductJson();
                            if (bottomAdBean.getProductType().equalsIgnoreCase("1")) {
                                CommodityDetailActivity.StartThis(getActivity(), url, json);
                            } else if (bottomAdBean.getProductType().equalsIgnoreCase("2")) {
                                Intent intent = new Intent(getContext(), TYFOH5Activity.class);
                                intent.putExtra(TYFOH5Activity.HTML_URL, url);
                                startActivity(intent);
                            }
                            adLayerLayout.setVisibility(View.GONE);
                            adLayerLayout.startAnimation(mOutAction);
                            Cache.getInstance().setHomeGreateAdClosed(true);
                        } else {
                            Intent intent = new Intent(getContext(), LoginActivity.class);
                            startActivityForResult(intent, CODE_REQUEST_LOGIN);
                        }
                    }
                }
            }
        });
        recyclerView.addOnScrollListener(new RecyclerView.OnScrollListener() {


            @Override
            public void onScrollStateChanged(RecyclerView recyclerView, int newState) {
                super.onScrollStateChanged(recyclerView, newState);
            }

            @Override
            public void onScrolled(RecyclerView recyclerView, int dx, int dy) {
                super.onScrolled(recyclerView, dx, dy);
                dyHeight += dy;
                if (null != bottomAdBean && !TextUtils.isEmpty(bottomAdBean.getImageUrl()) && !Cache.getInstance().isHomeGreateAdClosed()) {
                    LinearLayoutManager layoutManager = (LinearLayoutManager) recyclerView.getLayoutManager();
                    int topPosition = layoutManager.findFirstVisibleItemPosition();
                    int height = recyclerView.getHeight();
                    if (dy > 0 && dyHeight >= height / 2 && adLayerLayout.getVisibility() != View.VISIBLE) {
                        adLayerLayout.setVisibility(View.VISIBLE);
                        adLayerLayout.startAnimation(mIntoAction);
                    } else if (dy < 0 && dyHeight < height / 2 && adLayerLayout.getVisibility() == View.VISIBLE) {
                        adLayerLayout.setVisibility(View.GONE);
                        adLayerLayout.startAnimation(mOutAction);
                    }
                }
                LinearLayoutManager layoutManager = (LinearLayoutManager) recyclerView.getLayoutManager();
                int topPosition = layoutManager.findFirstVisibleItemPosition();
                RecyclerView.LayoutManager manager = recyclerView.getLayoutManager();
                View topView = layoutManager.findViewByPosition(topPosition);
                if (null != topView && recyclerView.getChildViewHolder(topView) instanceof HomeLiveHolder) {
                    int bottom = topView.getBottom();
                    int height = topView.getHeight();
                    if (dy > 0) {
                        if (bottom < height  / 10) {
                            HomeLiveHolder liveHolder = (HomeLiveHolder) recyclerView.getChildViewHolder(topView);
                            liveHolder.setLiveMute(true);
                            liveHolder.onIPause();
                        }
                    } else if (dy < 0) {
                        if (bottom > height  / 10) {
                            HomeLiveHolder liveHolder = (HomeLiveHolder) recyclerView.getChildViewHolder(topView);
                            if(!liveHolder.isResuming()) {
                                liveHolder.setLiveMute(true);
                                liveHolder.onIResume();
                            }
                        }
                    }
                }
            }
        });
    }

    @Override
    protected boolean onFragmentShow(boolean isFirst, boolean isCallFromResume) {
        setShowCityState(Cache.getInstance().isCityShow());
        if (isFirst) {
            //首次显示的时候，自动刷新数据
            refreshLayout.autoRefresh();
        }
        if (adapter != null) {
            adapter.onResume();
        }
        JLog.e("okh  last time=" + lastGetTime);
        if (lastGetTime > 0) {
            long ca = SystemClock.elapsedRealtime() - lastGetTime;
            JLog.e("okh  will send msg  ca=" + ca);
            if (ca >= SPACE_GET_EXPRESS) {
                handler.sendEmptyMessage(WHAT_GET_EXPRESS);
            } else {
                handler.sendEmptyMessageDelayed(WHAT_GET_EXPRESS, SPACE_GET_EXPRESS - ca);
            }
        }
        return super.onFragmentShow(isFirst, isCallFromResume);
    }

    private Message createExpressGetMsg() {
        Message msg = Message.obtain();
        msg.what = WHAT_GET_EXPRESS;
        return msg;
    }

    private void parseMsg(Message msg) {
        if (msg.what == WHAT_GET_EXPRESS && !isShowLuZhou) {
            handler.removeMessages(WHAT_GET_EXPRESS);
            lastGetTime = SystemClock.elapsedRealtime();

            handler.sendEmptyMessageDelayed(WHAT_GET_EXPRESS, SPACE_GET_EXPRESS);
        }
    }

    /**
     * 获取精选模块 多个类型的显示数据。
     */
    private void getChannelList() {
        if (TextUtils.isEmpty(channelUrl)) {
            toast("数据错误");
            JLog.e("int " + this.getClass().getSimpleName() + " url wrong ::" + channelUrl);
            refreshLayout.refreshComplete();
            return;
        }
        NetUtils.getNetAdapter().getChannelArray(getOwnerName(), channelUrl, new AbsListNetCallback<FocusColumn>(ListTypeUtils.FocusColums()) {
            @Override
            public void onSuc(List<FocusColumn> focusColumns) {
                if (ListUtils.isListValued(focusColumns)) {
                    resetUrlTemps();
                    for (FocusColumn fc : focusColumns) {
                        if (fc != null) {
                            switch (fc.getSubChannelType()) {
                                case GreatestAdapter.VIEWTYPE_BANNER:
                                    bannerUrlTemp = fc.getChannelUrl();
                                    break;
                                case GreatestAdapter.VIEWTYPE_EXPRESS:
                                    expressUrlTemp = fc.getChannelUrl();
                                    break;
                                case GreatestAdapter.VIEWTYPE_LIVE:
                                    liveUrlTemp = fc.getChannelUrl();
                                    break;
                                case GreatestAdapter.VIEWTYPE_NEWS_24:
                                    hour24UrlTemp = fc.getChannelUrl();
                                    break;
                                case GreatestAdapter.VIEWTYPE_POPULAR:
                                    popularUrlTemp = fc.getChannelUrl();
                                    break;
                            }
                        }
                    }
                    if (dataAddHelper == null) {
                        dataAddHelper = new GreatestDataAddHelper();
                    }
                    lastGetTime = SystemClock.elapsedRealtime();
                    handler.removeMessages(WHAT_GET_EXPRESS);
                    handler.sendEmptyMessageDelayed(WHAT_GET_EXPRESS, SPACE_GET_EXPRESS);
                    if (!getNewsArray(bannerUrlTemp, GreatestAdapter.VIEWTYPE_BANNER)) {
                        dataAddHelper.removeUpItem(GreatestAdapter.VIEWTYPE_BANNER);
                    }

                    getFloatAd();
                }
            }

            @Override
            public void onError(Throwable ex, String errorMsg) {
                super.onError(ex, errorMsg);
                refreshLayout.refreshComplete();
            }
        });
    }

    private void getFloatAd() {
        SharedPreferencesUtil.setParam(getActivity(), FLOAT_AD_SHOW, false);

        String url = "/sctv/advert.json";
        NetUtils.getNetAdapter().getAdInfo(getOwnerName(), Constances.ST_BASE_URL + url, new AbsNetCallBack<AdvertDataVo>(AdvertDataVo.class) {
            @Override
            public void onSuc(AdvertDataVo advert) {
                if (ListUtils.isListValued(advert.getAdvertData())) {
                    List<AdvertBean> advertList = advert.getAdvertData();
                    AdvertBean advertBean = null;
                    for (int i = 0; i < advertList.size(); i++) {
                        if (advertList.get(i).getPosition() == 1) {
                            advertBean = advertList.get(i);//首页浮层广告
                        } else if (advertList.get(i).getPosition() == 2) {
                            bottomAdBean = advertList.get(i);
                        }
                    }
                    if (advertBean != null && isFirst && !Cache.getInstance().isStartAdClicked()) {
                        int count = (int) SharedPreferencesUtil.getParam(getActivity(), String.valueOf(advertBean.getVersionCode()), 0);
                        if (count <= advertBean.getShowCount() && !TextUtils.isEmpty(advertBean.getImageUrl())) {
                            Intent intent = new Intent(getActivity(), FloatAdActivity.class);
                            intent.putExtra(BaseActivity.EX_DATA, advertBean);
                            startActivity(intent);
                            getActivity().overridePendingTransition(0, 0);
                        }
                    }
                    if (null != bottomAdBean && !TextUtils.isEmpty(bottomAdBean.getImageUrl())) {
                        GlideUtil.getGlid(getContext(), bottomAdBean.getImageUrl()).into(adLayer);
                    }
                }
            }

            @Override
            public void onEnd() {
                super.onEnd();
                isFirst = false;
            }
        });

    }

    @Override
    protected void onFragmentUnShowed(boolean isCallFromPause) {
        if (adapter != null) {
            adapter.onPause();
        }
        handler.removeMessages(WHAT_GET_EXPRESS);
        super.onFragmentUnShowed(isCallFromPause);
    }

//    @Override
//    public void onPause() {
//        if (adapter != null) {
//            adapter.onPause();
//        }
//        super.onPause();
//    }

    @Override
    public void onDestroy() {
        if (adapter != null) {
            adapter.onDestory();
            adapter = null;
        }
        super.onDestroy();
    }


    private BasePlayerView liveVideoView;

    /**
     * 初始化播放器，让播放器可以全屏
     */
    public void initPlayer(BasePlayerView player) {
        if (null != player) {
            initVideoPlayer(player);
        }
    }

    public void showNetDialog(BasePlayerView videoView) {
        liveVideoView = videoView;
        if (Cache.getInstance().isCheckNet()) {
            videoView.startPlayLogic();
            return;
        }
        if (netModeDiaFragment == null) {
            netModeDiaFragment = new NetModeDiaFragment();
        }
        if (!netModeDiaFragment.isAdded()) {
            netModeDiaFragment.setCallBack(netCallBack);
            netModeDiaFragment.show(getFragmentManager(), NET_TAG);
        }
    }

    BaseDialogFragment.ICallBack netCallBack = new BaseDialogFragment.ICallBack() {
        @Override
        public void onCallBackMsg(BaseDialogFragment fragment, Message msg) {
            if (msg.what == NetModeDiaFragment.NO_TAG) {
//                floatVideoUtils.stopVideoView();
            } else if (msg.what == NetModeDiaFragment.OK_TAG) {
                Cache.getInstance().setCheckNet(true);
                if (null != liveVideoView) {
                    liveVideoView.startPlayLogic();
                }
            }
        }
    };
//    /**
//     * 获取 精选--快讯数据
//     *
//     * @param url
//     * @return
//     */
//    private int getExpressChannel(String url) {
//        if (TextUtils.isEmpty(url)) {
//            return 0;
//        }
//        if (!groupOrderHelper.addOne(30)) {
//            return 1;
//        }
//        NetUtils.getNetAdapter().getChannelArray(getOwnerName(), url, new AbsNetCallBack<List<FocusColumn>>(ListTypeUtils.FocusColums()) {
//            @Override
//            public void onSuc(List<FocusColumn> focusColumns) {
//                if (ListUtils.isListValued(focusColumns)) {
//                    FocusColumn fc = focusColumns.get(0);
//                    if (fc == null) {
//                        return;
//                    }
//                    newsFlashType = fc.getNewsFlashType();
//                    if (getNewsArray(fc.getChannelUrl(), GreatestAdapter.VIEWTYPE_EXPRESS) <= 0) {
//                        dataAddHelper.removeUpItem(GreatestAdapter.VIEWTYPE_EXPRESS);
//                    }
//                }
//            }
//
//            @Override
//            public void onEnd() {
//                super.onEnd();
//                onNetFinish(30);
//            }
//        });
//        return 2;
//    }

    /**
     * 获取首页精选-专题
     *
     * @param url
     * @return
     */
    private boolean getSpecialData(String url) {
        if (TextUtils.isEmpty(url)) {
            return false;
        }
        if (!groupOrderHelper.addOne(GreatestAdapter.VIEWTYPE_SPECIAL)) {
            return false;
        }
        NetUtils.getNetAdapter().getNewsPage(getOwnerName(), url, 0, new AbsListNetCallback<NewsItem>(null) {
            @Override
            public void onSuc(List<NewsItem> newsItems) {
                JLog.e("number ", "--------getSpecialData");
                List<NewsItem> list = new ArrayList<>();
                if (ListUtils.isListValued(newsItems)) {
                    int size = 5;
                    if (newsItems.size() < 5) {
                        size = newsItems.size();
                    }
                    for (int i = 0; i < size; i++) {
                        list.add(newsItems.get(i));
                    }
                    HomeListItem hb = new HomeListItem();
                    hb.setNewsItemList(list);
                    hb.setViewType(GreatestAdapter.VIEWTYPE_SPECIAL);
//                    hb.setSubUrl(homePopular.getMoreList());
                    dataAddHelper.setUpDatas(getContext(), hb, GreatestAdapter.VIEWTYPE_SPECIAL);//暂时使用calledIndex来保存mode
                } else {
                    dataAddHelper.removeUpItem(GreatestAdapter.VIEWTYPE_SPECIAL);//暂时使用calledIndex来保存mode
                }


            }

            @Override
            public void onError(Throwable ex, String errorMsg) {
            }

            @Override
            public void onEnd() {
                super.onEnd();

                if (!getNews24Date(news24Domain)) {
                    dataAddHelper.remove24data();
                }
                onNetFinish(GreatestAdapter.VIEWTYPE_SPECIAL);
            }
        });
        return true;
    }


    /**
     * 获取 精选--热门视频数据
     *
     * @param url
     * @return
     */
    private boolean getHomePopular(String url) {
        if (TextUtils.isEmpty(url)) {
            return false;
        }
        if (!groupOrderHelper.addOne(GreatestAdapter.VIEWTYPE_POPULAR)) {
            return false;
        }
        NetUtils.getNetAdapter().getHomePopular(getOwnerName(), url, new AbsNetCallBack<HomePopular>(HomePopular.class) {
            @Override
            public void onSuc(HomePopular homePopular) {
                JLog.e("number ", "--------getHomePopular");
                if (homePopular != null && ListUtils.isListValued(homePopular.getNewsList())) {
                    HomeListItem hb = new HomeListItem();
                    hb.setNewsItemList(homePopular.getNewsList());
                    hb.setViewType(GreatestAdapter.VIEWTYPE_POPULAR);
                    hb.setSubUrl(homePopular.getMoreList());
                    Cache.getInstance().setHotVideoUrl(homePopular.getMoreList());
//                    if (ListUtils.isListValued(homePopular.getMoreList())) {
//                        NewsItem ni = homePopular.getMoreList().get(0);
//                        hb.setSubUrl(ni.getNewsUrl());
//                    }
                    dataAddHelper.setUpDatas(getContext(), hb, GreatestAdapter.VIEWTYPE_POPULAR);//暂时使用calledIndex来保存mode
                } else {
                    dataAddHelper.removeUpItem(GreatestAdapter.VIEWTYPE_POPULAR);//暂时使用calledIndex来保存mode
                }
            }

            @Override
            public void onEnd() {
                super.onEnd();
                List<NewsItem> li = new ArrayList<>();
                List<IListShowData> tempList = new ArrayList<>();
                int count = 0;
                int size = newsList.size();
                for (int i = 0; i < size; i++) {
                    if (newsList.get(0) instanceof NewsItem) {
                        count++;
                        NewsItem item = (NewsItem) newsList.get(0);
                        if (li.size() > 0) {
                            item.setAfterTitleMode(-1);//改变左侧时间线标识、行分割线的显示状态
                        } else {
                            item.setAfterTitleMode(2);//改变左侧时间线标识、行分割线的显示状态
                        }
                        li.add(item);
                    }
                    newsList.remove(0);
                    if (count == 3) {
                        break;
                    }
                }
                tempList.addAll(newsList);
                newsList.clear();
                newsList.addAll(tempList);
                HomeListItem hb = new HomeListItem();
                hb.setNewsItemList(li);
                hb.setViewType(GreatestAdapter.VIEWTYPE_TOP3_NEWS);

                dataAddHelper.setUpDatas(getContext(), hb, GreatestAdapter.VIEWTYPE_TOP3_NEWS);//暂时使用calledIndex来保存mode
//                dataAddHelper.addTop24DataTopThree(getContext(), li, true);

                if (!getTimeLineList()) {
                    dataAddHelper.removeUpItem(GreatestAdapter.VIEWTYPE_ANCHORS);
                }
                onNetFinish(GreatestAdapter.VIEWTYPE_POPULAR);//暂时使用calledIndex来保存mode
            }
        });
        return true;
    }

    /**
     * 主播动态 数据请求（主播发表的内容）
     */
    private boolean getTimeLineList() {
        if (!groupOrderHelper.addOne(GreatestAdapter.VIEWTYPE_ANCHORS)) {
            return false;
        }
        int index = 0;
        int ANCHOR_SCTV_TYPE = 0;
        HashMap<String, Object> param = new HashMap<>();
        param.put("anchorId", "");
        param.put("capacity", 1);
        param.put("index", index);
        param.put("requestType", ANCHOR_SCTV_TYPE);
        param.put("siteNumber", Constances.SITE_ID);
        FUsers user = UserManager.getInstance().getUser();
        if (user != null && !TextUtils.isEmpty(user.getUserId())) {
            param.put("userId", user.getUserId());
        } else {
            param.put("userId", "");
        }
        NetUtils.getNetAdapter().getTimelineList(getOwnerName(), param, new AbsListNetCallback<ADynamicsItem>(ADynamicsItem.class) {
            @Override
            public void onSuc(List<ADynamicsItem> anchortimelines) {
                List<ADynamicsItem> dyDatas = new ArrayList<>();
                if (ListUtils.isListValued(anchortimelines)) {
                    ADynamicsItem firstItem = anchortimelines.get(0);
                    firstItem.setDynamics(true);
                    firstItem.setSticky(true);
                    firstItem.setViewType(GreatestAdapter.VIEWTYPE_ANCHORS);
//                    dyDatas.addAll(0, anchortimelines);
                    dataAddHelper.setUpDatas(getContext(), firstItem, GreatestAdapter.VIEWTYPE_ANCHORS);//暂时使用calledIndex来保存mode
                }

            }

            @Override
            public List<ADynamicsItem> doInBackground(List<ADynamicsItem> aDynamicsItems) {
                if (aDynamicsItems != null) {
                    for (ADynamicsItem item : aDynamicsItems) {
                        item.setViewType(AnchorHomePageAdapter.VIEWTYPE_DYNAMICS);
                    }
                }

                return super.doInBackground(aDynamicsItems);
            }

            @Override
            public void onEnd() {
                super.onEnd();
                if (null != newsList && newsList.size() > 1 && newsList.get(0) instanceof Titles) {
                    newsList.remove(0);
                }
                dataAddHelper.addOrSet24Datass(getContext(), newsList, true);
                onNetFinish(GreatestAdapter.VIEWTYPE_ANCHORS);//暂时使用calledIndex来保存mode
            }


        });
        return true;

    }

    /**
     * 获取 精选-banner数据
     *
     * @param url
     * @param mode
     * @return
     */
    private boolean getNewsArray(String url, final int mode) {
        if (TextUtils.isEmpty(url)) {
            JLog.e("int " + this.getClass().getSimpleName() + " url wrong ::" + url + "  mode=" + mode);
            return false;
        }
        if (!groupOrderHelper.addOne(mode)) {
            return false;
        }
        NetUtils.getNetAdapter().getNewsArray(getOwnerName(), url, new AbsListNetCallback<NewsItem>(ListTypeUtils.NewsItem(), mode) {//暂时使用calledIndex来保存mode
            @Override
            public void onSuc(List<NewsItem> newsItems) {
                if (ListUtils.isListValued(newsItems)) {
                    HomeListItem hb = new HomeListItem();
                    hb.setNewsItemList(newsItems);
                    hb.setViewType(GreatestAdapter.VIEWTYPE_BANNER);
                    dataAddHelper.setUpDatas(getContext(), hb, GreatestAdapter.VIEWTYPE_BANNER);//暂时使用calledIndex来保存mode
                } else {
                    dataAddHelper.removeUpItem(calledIndex);//暂时使用calledIndex来保存mode
                }
            }

            @Override
            public void onEnd() {
                super.onEnd();
                if (!getLiveArray(liveUrlTemp)) {
                    dataAddHelper.removeUpItem(GreatestAdapter.VIEWTYPE_LIVE);
                }
//                if (!getSpecialData(specialUrlTemp)) {
//                    dataAddHelper.removeUpItem(GreatestAdapter.VIEWTYPE_SPECIAL);
//                }
                onNetFinish(calledIndex);//暂时使用calledIndex来保存mode
            }
        });
        return true;
    }

    /**
     * 获取精选--直播数据
     *
     * @param url
     * @return
     */
    private boolean getLiveArray(String url) {
        if (TextUtils.isEmpty(url)) {
            JLog.e("int " + this.getClass().getSimpleName() + " live url wrong ::" + url);
            return false;
        }
        if (!groupOrderHelper.addOne(GreatestAdapter.VIEWTYPE_LIVE)) {
            return false;
        }
        NetUtils.getNetAdapter().getLiveArray(getOwnerName(), url, new AbsListNetCallback<LiveItem>(ListTypeUtils.LiveItem()) {
            @Override
            public void onSuc(List<LiveItem> liveItems) {
                JLog.e("number ", "--------getLiveArray");
                if (ListUtils.isListValued(liveItems)) {
                    HomeLive hli = new HomeLive();
                    hli.setLiveList(liveItems);
                    hli.setViewType(GreatestAdapter.VIEWTYPE_LIVE);
//                    dataAddHelper.setLiveData(getContext(), hli);
                    dataAddHelper.setUpDatas(getContext(), hli, GreatestAdapter.VIEWTYPE_LIVE);//暂时使用calledIndex来保存mode
                } else {
                    dataAddHelper.removeUpItem(GreatestAdapter.VIEWTYPE_LIVE);
                }
            }

            @Override
            public void onEnd() {
                super.onEnd();
                if (!getNews24Date(news24Domain)) {
                    dataAddHelper.remove24data();
                }

                onNetFinish(GreatestAdapter.VIEWTYPE_LIVE);
            }
        });
        return true;
    }

    /**
     * 获取 精选--视讯新闻数据
     *
     * @return
     */
    private boolean getNews24Date(final String news24Domain) {
        String news24Url = hour24UrlTemp;
        if (Cache.getInstance().isCityShow()) {
            news24Url = Cache.getInstance().getChoosedCityNewsUrl();
            newKey = GreatestAdapter.VIEWTYPE_LUZHOU_NEWS;
        }
        if (TextUtils.isEmpty(news24Url)) {
            JLog.e("int " + this.getClass().getSimpleName() + " 24h url wrong ::" + news24Url + "  page=" + current24Page);
            return false;
        }
        if (!groupOrderHelper.addOne(newKey)) {
            return false;
        }
        NetUtils.getNetAdapter().getNewsDateArray(getOwnerName(), news24Url, new AbsListNetCallback<NewsDate>(ListTypeUtils.NewsItem()) {
            private int te = 0;

            @Override
            public void onSuc(List<NewsDate> newsItems) {
                JLog.e("number ", "--------getNews24Date");
                if (ListUtils.isListValued(newsItems)) {
                    for (int i = 0; i < newsItems.size(); i++) {
                        newsItems.get(i).setNewsListUrl(news24Domain + newsItems.get(i).getNewsListUrl());
                    }
                    init24Helper().setDates(newsItems);

                    getNews24Page(news24Domain, true);
                }
            }

            @Override
            public List<NewsDate> doInBackground(List<NewsDate> newsDates) {
                if (ListUtils.isListValued(newsDates)) {
                    NewsDate stick = null;
                    if (newsDates.get(0).getNewsDate().equalsIgnoreCase("isStick")) {
                        stick = newsDates.get(0);
                        newsDates.remove(0);
                    }
                    if (newsDates.size() > 2) {
                        Collections.sort(newsDates, new NewsDateComparator());
                    }
                    if (null != stick) {
                        newsDates.add(0, stick);
                    }
                }
                return super.doInBackground(newsDates);
            }

            @Override
            public void onError(Throwable ex, String errorMsg) {
                super.onError(ex, errorMsg);
            }

            @Override
            public void onEnd() {
                super.onEnd();
                onNetFinish(newKey);
            }
        });
        return true;
    }

    private MutilDateNewsGetHelper init24Helper() {
        if (hour24GetHelper == null) {
            hour24GetHelper = new MutilDateNewsGetHelper(this);
            hour24GetHelper.setShouldSetTitleAfter(true);
        }
        return hour24GetHelper;
    }

    private boolean getNews24Page(final String news24Domain, final boolean reset) {
        if (!init24Helper().hasValuedDate()) {
            dataAddHelper.remove24data();
            return false;
        }
        if (!groupOrderHelper.addOne(241)) {
            return false;
        }
        isReset = reset;
        hour24GetHelper.getNewsList(30, reset
                , new AbsListNetCallback<IListShowData>(IListShowData.class) {

                    @Override
                    public void onSuc(List<IListShowData> newsItems) {
                        if (ListUtils.isListValued(newsItems)) {
                            if (Cache.getInstance().isCityShow()) {
                                for (int i = 0; i < newsItems.size(); i++) {
                                    IListShowData t = newsItems.get(i);
                                    if (t instanceof NewsItem) {
                                        ((NewsItem) newsItems.get(i)).setNewsImage(news24Domain + ((NewsItem) newsItems.get(i)).getNewsImage());
                                        ((NewsItem) newsItems.get(i)).setNewsUrl(news24Domain + ((NewsItem) newsItems.get(i)).getNewsUrl());
                                        ((NewsItem) newsItems.get(i)).setLuzhouShow(true);
                                    }
                                }
                            }
                            if (isRefresh) {
                                newsList.clear();
//                                List<NewsItem> li = new ArrayList<>();
//                                int count = 0;
//                                int size = newsItems.size();
//                                for (int i = 0; i < size; i++) {
//                                    if (newsItems.get(0) instanceof NewsItem) {
//                                        count++;
//                                        NewsItem item = (NewsItem) newsItems.get(0);
//                                        if (li.size() > 0) {
//                                            item.setAfterTitleMode(-1);//改变左侧时间线标识、行分割线的显示状态
//                                        }
//                                        li.add(item);
//                                    }
//                                    newsItems.remove(0);
//                                    if (count == 2) {
//                                        break;
//                                    }
//                                }
                                newsList.addAll(newsItems);
//                                if (null != newsList && newsList.size() > 1 && newsList.get(0) instanceof Titles) {
//                                    newsList.remove(0);
//                                }
                                dataAddHelper.addOrSet24Datass(getContext(), newsList, true);
                                isRefresh = false;
                            } else {
                                if (null != newsList && newsList.size() == 0 && null != newsItems && newsItems.size() > 1 && newsItems.get(0) instanceof Titles) {
                                    newsItems.remove(0);
                                }
                                dataAddHelper.addOrSet24Datass(getContext(), newsItems, reset);
                            }
                        } else {
                            if (calledIndex <= 0) {
                                dataAddHelper.remove24data();
                                current24Page = calledIndex;
                            }
                        }
                    }

                    @Override
                    public void onError(Throwable ex, String errorMsg) {
                        super.onError(ex, errorMsg);
                    }

                    @Override
                    public void onEnd() {
                        super.onEnd();
//                        if (null != newsList && newsList.size() > 1 && newsList.get(0) instanceof Titles) {
//                            newsList.remove(0);
//                        }
//                        dataAddHelper.addOrSet24Datass(getContext(), newsList, true);
                        onNetFinish(241);
                    }
                });
        return true;
    }

    private List<? extends IListShowData> parse24Datas(List<NewsItem> list) {
        if (secTitlePos > 0) {
            return list;
        }
        ArrayList<IListShowData> li = new ArrayList<>();
        if (first24TitleDateTemp == null) {
            Date date = DateUtils.getDataDate(list.get(0));
            if (date == null) {
                return list;
            }
            Calendar c = Calendar.getInstance();
            c.setTimeInMillis(date.getTime());
            c.set(c.get(Calendar.YEAR), c.get(Calendar.MONTH), c.get(Calendar.DAY_OF_MONTH), 0, 0, 0);
            date.setTime(c.getTimeInMillis());
            first24TitleDateTemp = date;
            Titles t = new Titles();
            t.setDateString(DateUtils.formatDate(date, "MM月dd日"));
            t.setViewType(GreatestAdapter.VIEWTYPE_TITLE_24);
            li.add(t);
        }
        int i = 0;
        while (list.size() > 0) {
            Date d = DateUtils.getDataDate(list.get(i));
            if (d != null) {
                if (d.before(first24TitleDateTemp)) {
                    secTitlePos = i;
                    Titles t = new Titles();
                    t.setDateString(DateUtils.formatDate(d, "MM月dd日"));
                    t.setViewType(GreatestAdapter.VIEWTYPE_TITLE_24_CONTINUE);
                    break;
                }
            }
            li.add(list.remove(i));
            i++;
        }
        if (list.size() > 0) {
            li.addAll(list);
        }

        return li;
    }

    /**
     * 获取泸州市的栏目数据
     */
    private void getLuZhouData() {
        String url = "lztv/index.json";
        NetUtils.getNetAdapter().getChannelArray(getOwnerName(), url, new AbsListNetCallback<FocusColumn>(null) {
            @Override
            public void onSuc(List<FocusColumn> fChannels) {
                closeProgress();
                if (null != fChannels) {
                    for (int i = 0; i < fChannels.size(); i++) {
                        if (fChannels.get(i).getChannelType().equalsIgnoreCase("1")) {
                            //获取到泸州市的精选接口
                            String greatestUrl = fChannels.get(i).getChannelUrl();
                            getLuZhouSubData(greatestUrl);
                        }
                    }
                }
            }

            @Override
            public void onError(Throwable ex, String errorMsg) {
                super.onError(ex, errorMsg);
                closeProgress();
            }
        });
    }

    /**
     * 获取到泸州市的新闻接口
     *
     * @param url
     */
    private void getLuZhouSubData(String url) {
        if (TextUtils.isEmpty(url)) {
            Toast.makeText(getContext(), "数据错误", Toast.LENGTH_LONG).show();
            return;
        }

        NetUtils.getNetAdapter().getChannelArray(getOwnerName(), url, new AbsListNetCallback<FocusColumn>(null) {
            @Override
            public void onSuc(List<FocusColumn> fChannels) {
                closeProgress();
                if (null != fChannels) {
                    for (int i = 0; i < fChannels.size(); i++) {
                        if (fChannels.get(i).getSubChannelType() == 5) {
                            //获取到泸州市的“热点新闻”接口
                            hour24UrlTemp = fChannels.get(i).getChannelUrl();
                            //使用首页精选中的新闻类型加载泸州市的新闻数据
//                            getNews24Date();
                        }
                    }
                }
            }

            @Override
            public void onError(Throwable ex, String errorMsg) {
                super.onError(ex, errorMsg);
                closeProgress();
            }
        });
    }

    @Override
    public void OnLivePaly(String liveId) {
        if (!TextUtils.isEmpty(liveId)) {
            initViewClickData(liveId);
        }
    }

    /**
     * 增加直播点击
     *
     * @param liveID
     */
    private void initViewClickData(final String liveID) {
        ArrayMap<String, Object> p = new ArrayMap<>();
        p.put("id", liveID);
        p.put("type", 1);//type（0.新闻 1.直播)
        NetUtils.getNetAdapter().addNewOrLivingClick(getOwnerName(), p, new AbsNetCallBack<SingleResult>(SingleResult.class) {
            @Override
            public void onSuc(SingleResult vo) {
                JLog.e("initViewClickData", "GreatestFragment liveID = "+liveID + vo.isSuccess());
            }

            @Override
            public void onEnd() {
                super.onEnd();
            }

            @Override
            public void onError(Throwable ex, String errorMsg) {
                super.onError(ex, errorMsg);
            }
        });


    }

    private synchronized void onNetFinish(int mode) {
        if (groupOrderHelper.removeOne(mode)) {
            refreshLayout.refreshComplete();
            refreshLayout.loadMoreComplete();
            refreshLayout.setLoadMoreEnabled(hour24GetHelper != null && !hour24GetHelper.hasGetAll());
        }
        if (adapter == null && dataAddHelper.hasDatas()) {
            adapter = dataAddHelper.getAdapter(getContext(),this,this);
            ArrayList<Pair<String, String>> pairs = new ArrayList<>();
            pairs.add(new Pair<>("页面", "首页"));
            pairs.add(new Pair<>("栏目", "精选"));
//            pairs.add(new Pair<>("行为类型", "点击"));
            adapter.setActiveClick(activeClick);
            adapter.setFragment(this);
            adapter.setPairs(pairs);
            adapter.setPlayingListener(this);
//            adapter.setAnchorListener(this);
            adapter.setSpecialListener(this);
//            adapter.setAnchorItemListener(this);
//            adapter.setEntranceClickListener(this);
            recyclerView.setAdapter(adapter);
        }
        if (isReset) {
            isReset = false;
            handler.postDelayed(new Runnable() {
                @Override
                public void run() {
                    recyclerView.smoothScrollToPosition(0);
////                    recyclerView.scrollTo(0,0);
//                    layoutManager.scrollToPositionWithOffset(0,0);
                }
            }, 700);
        }
    }

    private void resetUrlTemps() {
        bannerUrlTemp = null;
        expressUrlTemp = null;
        hour24UrlTemp = null;
        liveUrlTemp = null;
        popularUrlTemp = null;
        current24Page = -1;
        first24TitleDateTemp = null;
        secTitlePos = -1;
    }

    public void setSpecialUrlTemp(String specialUrlTemp) {
        this.specialUrlTemp = specialUrlTemp;
    }

    public void setAnchorsUrlTemp(String anchorsUrlTemp) {
        this.anchorsUrlTemp = anchorsUrlTemp;
    }

    /**
     * 切换是否显示泸州的新闻模式
     *
     * @param showLuZhou
     */
    public void setShowCityState(boolean showLuZhou) {
        if (isShowLuZhou != showLuZhou) {
            isShowLuZhou = showLuZhou;
//            if (showLuZhou) {
//                //显示泸州市模式
//                if (dataAddHelper == null) {
//                    dataAddHelper = new GreatestDataAddHelper();
//                }
////                dataAddHelper.removeUpItem(GreatestAdapter.VIEWTYPE_EXPRESS);
////                dataAddHelper.removeUpItem(GreatestAdapter.VIEWTYPE_LIVE);
////                dataAddHelper.removeUpItem(GreatestAdapter.VIEWTYPE_POPULAR);
////                dataAddHelper.removeUpItem(GreatestAdapter.VIEWTYPE_TITLE_24);
////                dataAddHelper.removeUpItem(GreatestAdapter.VIEWTYPE_TITLE_24_CONTINUE);
////                dataAddHelper.removeUpItem(GreatestAdapter.VIEWTYPE_NEWS_24);
//                dataAddHelper.cleanGreatestdata();
//                getLuZhouData();
//            } else {
//                if (dataAddHelper == null) {
//                    dataAddHelper = new GreatestDataAddHelper();
//                }
//                //切换为原始模式:清楚之前泸州市的新闻数据，重新加载
//                dataAddHelper.removeUpItem(GreatestAdapter.VIEWTYPE_LUZHOU_NEWS);
//                dataAddHelper.cleanGreatestdata();
//                getChannelList();
//            }
//            dataAddHelper.cleanGreatestdata();
            refreshLayout.autoRefresh();
        }
    }

    /**
     * 快讯重磅跳转
     */
    OnItemInternalClick activeClick = new OnItemInternalClick() {
        @Override
        public void onItemInternalClick(View itemView, View view, int position) {
            HomeListItem homeListItem = null;
            if (view == null) {
                homeListItem = (HomeListItem) itemView.getTag(R.id.adapter_item_data_key);
            } else {
                homeListItem = (HomeListItem) itemView.getTag(R.id.adapter_item_data_key);
            }
            Intent intent = null;
            ArrayList<Pair<String, String>> pairs = new ArrayList<>();
            pairs.add(new Pair<>("页面", "首页"));
            pairs.add(new Pair<>("栏目", "精选"));
            pairs.add(new Pair<>("行为类型", "点击"));
            if (homeListItem.getSubType() == 1) {
                ((HomeFragment) getParentFragment()).setCurrentSelectIndex();
//                intent = new Intent(getContext(), MainActivity.class);
//                intent.putExtra(BaseActivity.EX_ID, homeListItem.getNewsItemList().get(position).getNewsId());
//                intent.addFlags(Intent.FLAG_ACTIVITY_REORDER_TO_FRONT);
//                startActivity(intent);
                pairs.add(new Pair<>("位置", "快讯"));
            } else if (homeListItem.getSubType() == 2) {
                pairs.add(new Pair<>("位置", "重磅"));
                HashMap<String, String> map = new HashMap<>();
                for (Pair<String, String> p : pairs) {
                    map.put(p.first, p.second);
                }
                SkipUtil.skipWithNewsItem(getContext(), homeListItem.getNewsItemList().get(position), map);
            }
            GridsumWebDissector.getInstance().trackEvent(GreatestFragment.this, "", homeListItem.getNewsItemList().get(position).getNewsTitle(), "", 200, pairs);

        }
    };

//    public void setAnchorChannelUrl(String anchorChannelUrl) {
//        this.anchorChannelUrl = anchorChannelUrl;
//    }

//    @Override
//    public void OnAnchorSelectMore() {
//        ((HomeFragment) getParentFragment()).setCurrentAnchorIndex();
//    }

    @Override
    public void OnSpecialSelectMore() {
        ((HomeFragment) getParentFragment()).setCurrentSpecialIndex();
    }
//
//    @Override
//    public void OnAnchorSelectItem(ADynamicsItem dyTemp) {
////        String contentVideoUrl = UrlUtils.linkUrls(Constances.ST_BASE_URL, dyTemp.getContentVideo());
////        SkipUtil.skipToVideoPlay(this, contentVideoUrl, dyTemp.getPlayedPos(), 0);
//        Intent intent = new Intent(getContext(), CommentDetailActivity.class);
//        intent.putExtra(EX_DATA, dyTemp);
//        intent.putExtra(EX_COMMENT_TYPE, 3);
//        startActivity(intent);
//    }
//
//    @Override
//    public void onEntranceClick(int clickType) {
//        switch (clickType) {
//            case 1:
//                Intent intent = new Intent(getContext(), AnchorActivity.class);
//                intent.putExtra(AnchorActivity.CHANNEL_URL, anchorsUrlTemp);
//                startActivity(intent);
//                break;
//            case 2:
//                Cache.getInstance().setHomeToAudio(true);
//                ((HomeFragment) getParentFragment()).setCurrentTvAudioIndex();
//                break;
//            case 3:
//                //更多，去积分商城
//                if (UserManager.isLoginS()) {
//                    ArrayList<Pair<String, String>> pairs = new ArrayList<>();
//                    pairs.add(new Pair<>("页面", "服务"));
//                    pairs.add(new Pair<>("行为类型", "点击"));
//                    GridsumWebDissector.getInstance().trackEvent(this, "", "更多商品", "", 200, pairs);
//                    IntegralStoreActivity.startThis(getContext());
//                } else {
//                    Intent intent1 = new Intent(getContext(), LoginActivity.class);
//                    startActivityForResult(intent1, CODE_REQUEST_LOGIN);
//                }
//                break;
//        }
//    }
//    private void sss() {
////        dataAddHelper = new GreatestDataAddHelper();
////        NewsItem item = NewsItem.createTestInstance(0, GreatestAdapter.VIEWTYPE_BANNER);
//////        list.add(item);
////        dataAddHelper.setBannerData(getContext(), item);
////        item = NewsItem.createTestInstance(0, GreatestAdapter.VIEWTYPE_EXPRESS);
//////        list.add(item1);
////        dataAddHelper.setExpressData(getContext(), item);
////        Titles ti = null;
//////        ti = new Titles();
//////        ti.setTitle(getString(R.string.hot_video));
//////        ti.setViewType(GreatestAdapter.VIEWTYPE_TITLE_24);
//////        list.add(ti);
////
////        HomeLive hl = new HomeLive();
////        hl.setViewType(GreatestAdapter.VIEWTYPE_LIVE);
////        String[] vs = getResources().getStringArray(R.array.test_lives);
////        String[] lss = getResources().getStringArray(R.array.test_long_strss);
////        int vsl = vs.length, lssl = lss.length;
////        ArrayList<LiveItem> ls = new ArrayList<>();
////        int si = (int) (Math.random() * 3 + 1);
////        for (int i = 0; i < si; i++) {
////            LiveItem li = new LiveItem();
////            li.setTitle(i + "-" + lss[(int) (Math.random() * lssl)]);
////            int m = (int) (Math.random() * vsl * 10);
////            if (m >= vsl) {
////                m = m % vsl;
////            }
////            li.setLiveUrl(vs[m]);
////            ls.add(li);
////        }
////        hl.setLiveList(ls);
////        dataAddHelper.setLiveData(getContext(), hl);
////
////        item = NewsItem.createTestInstance(0, GreatestAdapter.VIEWTYPE_POPULAR);
//////        list.add(item2);
////        dataAddHelper.setPopularData(getContext(), item);
////        List<IListShowData> list = new ArrayList<>();
////        ti = new Titles();
//////        JLog.e("30dp=" + DensityUtil.dip2px(30) + "   " + getResources().getDimensionPixelOffset(R.dimen.test));
////        ti.setDateString("7月6日");
////        ti.setViewType(GreatestAdapter.VIEWTYPE_TITLE_24);
////        list.add(ti);
////        for (int i = 0; i < 6; i++) {
////            list.add(NewsItem.createTestInstance(i, GreatestAdapter.VIEWTYPE_NEWS_24));
////        }
////        ti = new Titles();
////        ti.setDateString("7月5日");
////        ti.setViewType(GreatestAdapter.VIEWTYPE_TITLE_24_CONTINUE);
////        list.add(ti);
////        for (int i = 0; i < 6; i++) {
////            list.add(NewsItem.createTestInstance(i == 0 ? -2 : i, GreatestAdapter.VIEWTYPE_NEWS_24));
////        }
////        dataAddHelper.addOrSet24Datas(getContext(), list, true);
////    }

}
